package microservicedemo.borrowservice.mapper;

import microservicedemo.borrowservice.po.BorrowRecord;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

public interface BorrowMapper {

    @Insert("insert into borrowrecord(username,borrow_book,borrow_date,return_date,status) values(#{username},#{borrowbook},#{borrowDate},#{returnDate},#{status})")
    void borrowBook(BorrowRecord borrowRecord);

    @Update("update borrowrecord set status=#{status} where id=#{id}")
    void returnBook(BorrowRecord borrowRecord);

    @Select("select * from borrowrecord where return_date < #{now}")
    @Results({
            @Result(property = "borrowbook", column = "borrow_book"),
            @Result(property = "borrowDate", column = "borrow_date"),
            @Result(property = "returnDate", column = "return_date")
    })
    List<BorrowRecord> getOverdueBook(LocalDate now);
}
